# 构建阶段
FROM alpine:3.18
MAINTAINER Yang <yangyufans@qq.com>
ENV REDIS_VERSION=8.2.2

RUN apk add --no-cache \
    build-base \
    linux-headers \
    tcl \
    wget \
    gcc \
    make \
    musl-dev \
    zlib-dev \
    openssl-dev \
    linux-headers

RUN cd / && wget http://download.redis.io/releases/redis-$REDIS_VERSION.tar.gz \
    && tar -zxvf redis-$REDIS_VERSION.tar.gz \
    && rm -rf redis-$REDIS_VERSION.tar.gz \
    && cd /redis-$REDIS_VERSION \

RUN make MALLOC=libc && make install

RUN cp /redis-$REDIS_VERSION/redis.conf /usr/local/bin/ && cd /

COPY start.sh /start.sh

RUN apk add --no-cache libgcc tzdata

RUN mkdir /redis /redis/conf /redis/logs /redis/data

RUN chmod +x /start.sh

RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

RUN sed -i 's/logfile ""/logfile "\/redis\/logs\/redis.log"/' /usr/local/bin/redis.conf && \
    sed -i 's/bind 127.0.0.1/#bind 127.0.0.1/' /usr/local/bin/redis.conf && \
    sed -i 's/dir .\//dir \/redis\/data\//' /usr/local/bin/redis.conf

EXPOSE 6379 16379

ENTRYPOINT ["/start.sh"]
